package cn.netty.exemple6;

import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;

public class SubReqServerHandle extends ChannelHandlerAdapter {


    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {

        if (msg instanceof Order){
            Order msg1 = (Order) msg;
            // do something
            System.out.println(msg1.toString());
            OrderResponse response = new OrderResponse();
            response.setMessage("is OK");
            ctx.writeAndFlush(response);

        }
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        System.out.println("client is error "+cause.getMessage());
        ctx.close();
    }
}
